﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Jinjia.Approve.Entity.Entity.JJFlow;
using Jinjia.Approve.Model.Input.JJFlow;
using Jinjia.Approve.Model.VM.JJFlow;
using Jinjia.Core.BaseInfrastructure.StorageModel.Model;

namespace Jinjia.Approve.IRepository.JJFlow
{
    public interface IFlowInstanceRepository
    {
        /// <summary>
        /// 此业务是否存在待审批或已经完成的审批记录
        /// </summary>
        /// <param name="modular_key">模块Key</param>
        /// <param name="template_id">审批流模板ID</param>
        /// <param name="biz_order_id">业务ID</param>
        /// <returns></returns>
        Task<List<jj_flow_instance>> IsExist(string modular_key, int template_id, string biz_order_id);

        /// <summary>
        /// 获取 非撤回状态的 Instance
        /// </summary>
        /// <param name="modular_key">模块Key</param>
        /// <param name="biz_order_id">业务ID</param>
        /// <returns></returns>
        Task<jj_flow_instance> GetInstanceInfo(string modular_key, string biz_order_id);

        /// <summary>
        /// 新增或修改
        /// </summary>
        /// <param name="data"></param>
        /// <returns>主键id</returns>
        Task<int> Save(jj_flow_instance data);

        /// <summary>
        /// 查询申请记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<jj_flow_instance> GetById(int id);

        /// <summary>
        /// 查询申请列表
        /// </summary>
        /// <param name="modular_key"></param>
        /// <param name="instanceIds"></param>
        /// <param name="status">状态, 默认为0审核中</param>
        /// <returns></returns>
        Task<List<jj_flow_instance>> GetByModularKeyAndInstanceIds(string modular_key,  List<int> instanceIds,string status = "0");

        /// <summary>
        /// 查询申请列表
        /// </summary>
        /// <param name="modular_key"></param>
        /// <param name="biz_order_id"></param>
        /// <returns></returns>
        Task<List<jj_flow_instance>> GetInstanceList(string modular_key, string biz_order_id);

        /// <summary>
        /// 我已审批操作的数据
        /// </summary>
        /// <param name="system_key"></param>
        /// <param name="big_modular_key"></param>
        /// <param name="modular_key"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<List<string>> GetUserProcessedBizOrderId(string system_key, string big_modular_key, string modular_key, int user_id);
        
        /// <summary>
        /// 获取我提交审核的数据
        /// </summary>
        /// <param name="system_key"></param>
        /// <param name="big_modular_key"></param>
        /// <param name="modular_key"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<List<string>> GetUserCreateApplyBizOrderId(string system_key, string big_modular_key, string modular_key, int user_id);

        /// <summary>
        /// 审批单列表
        /// </summary>
        /// <param name="searchCondition"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        Task<PageListSearchResultVM<JJInstanceViewModel>> GetInstancePageList(JJInstanceSearchCondition searchCondition, int user_id);

        /// <summary>
        /// 调教获取审批列表
        /// </summary>
        /// <param name="expression"></param>
        /// <returns></returns>
        Task<List<jj_flow_instance>> GetListAsync(Expression<Func<jj_flow_instance, bool>> expression);
    }
}